import React from 'react';
import DecideTable from 'src/components/DecideTable';
import DecisionMatrix from 'src/components/DecisionMatrix';
import RuleSet from './ruleSet';
import RulesScore from './rulesScore';
import RiskWeight from './riskWeight';
import { STRATEGY_MODE } from 'src/utils/constant';

export default function TestResult(props) {
  const { value, logs = {}, actions, variable, using_variables } = props;

  // 测试详情
  const renderTestResult = () => {
    if (!value || !Object.keys(value).length) return;
    const { config } = value;
    const { mode } = JSON.parse(config);

    switch (mode.code) {
      case STRATEGY_MODE._RULESET:
        return (
          <RuleSet
            actions={actions}
            value={mode.rule_set}
            logs={logs}
            variable={variable}
            using_variables={using_variables}
          />
        );
      case STRATEGY_MODE._WEIGHT:
        return (
          <RiskWeight
            actions={actions}
            value={mode.risk_weight}
            logs={logs}
            variable={variable}
            using_variables={using_variables}
          />
        );
      case STRATEGY_MODE._SCORE_CARD:
        return (
          <RulesScore
            actions={actions}
            value={mode.score_card}
            logs={logs}
            variable={variable}
            using_variables={using_variables}
          />
        );
      case STRATEGY_MODE._DECISION_TABLE:
        return (
          <DecideTable
            value={mode.decision_table}
            disabled
            logs={logs}
            actions={actions}
            variable={variable}
            using_variables={using_variables}
          />
        );
      case STRATEGY_MODE._DECISION_MATRIX:
        return (
          <DecisionMatrix
            value={mode.decision_matrix}
            disabled={true}
            logs={logs}
            variable={variable}
            using_variables={using_variables}
            actions={actions}
          />
        );
      default:
        break;
    }
  };

  return <div>{renderTestResult()}</div>;
}
